package it.polimi.traveldream.web.beans.employee;

import it.polimi.traveldream.ejbclient.dtos.ParticipationDTO;
import it.polimi.traveldream.ejbclient.eaos.ParticipationServiceEAO;
import it.polimi.traveldream.utils.exceptions.NotSuchProductException;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;

@ManagedBean(name="listParticipations")
@RequestScoped
public class ListParticipations {
	@EJB
	private ParticipationServiceEAO pService;
	private List<ParticipationDTO> participations;
	@ManagedProperty(value="#{personalHomeEmployee.idPackage}")
	private int idPackage;
	
	public ListParticipations() {
	}
	
	@PostConstruct
	public void init() {
		try {
			participations = pService.searchParticipations(idPackage, false);
		} catch (NotSuchProductException e) {
			participations = new ArrayList<ParticipationDTO>();
		}
		try {
			List<ParticipationDTO> participationsOverpast = pService.searchParticipations(idPackage, true);
			participations.addAll(participationsOverpast);
		} catch (NotSuchProductException e) {
		}	
	}

	public List<ParticipationDTO> getParticipations() {
		return participations;
	}

	public void setParticipations(List<ParticipationDTO> participations) {
		this.participations = participations;
	}

	public int getIdPackage() {
		return idPackage;
	}

	public void setIdPackage(int idPackage) {
		this.idPackage = idPackage;
	}
	
}
